package com.interesting.client.UI.commonActivity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ProgressBar;

import com.interesting.R;
import com.interesting.client.application.AppHolder;
import com.interesting.client.widget.ZoomImageView;

public class BrowserBigPicActivity1 extends Activity {

	private ProgressBar progressBar;
	private FrameLayout layout;
	private String msg;
//	private Bitmap bitmap;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zoom_image_activity);
		WindowManager.LayoutParams params = getWindow().getAttributes();
		params.width = getResources().getDimensionPixelOffset(R.dimen.browser_pic_activity_width);
		getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
		
		msg = getIntent().getStringExtra("msg");
		
		layout=(FrameLayout)findViewById(R.id.picture_layout);
//		imageView = (ZoomImageView) findViewById(R.id.picture_item_image);
		progressBar=(ProgressBar)findViewById(R.id.picture_progress);
		//设置进入和退出效果
		overridePendingTransition(R.anim.zoom_enter,  
                R.anim.zoom_exit);
		
		if(savedInstanceState==null)
			new loadImage().execute();
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putSerializable("msg", msg);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	class loadImage extends AsyncTask<String, Integer, Bitmap>{

		@Override
		protected Bitmap doInBackground(String... params) {
			Bitmap bitmap = AppHolder.getInsatnce().imageLoader.getBitmap(msg);
			return bitmap;
		}

		@Override
		protected void onPostExecute(Bitmap result) {
			progressBar.setVisibility(View.GONE);
			if (result != null) {
				ZoomImageView imageView=new ZoomImageView(getApplicationContext());
				FrameLayout.LayoutParams params=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
				params.gravity=Gravity.CENTER;
				imageView.setLayoutParams(params);
				imageView.setImageBitmap(result);
				imageView.setImage(result);
				layout.addView(imageView);
			}
			
		}
		
		
	}
}
